import Vue from 'vue'
import VueRouter from 'vue-router'
// import Login from '../components/login.vue'
const Login = () => import(/* webpackChunkName: "login-home-welcom" */ '../components/login.vue')
// import Home from '../components/Home.vue'
const Home = () => import(/* webpackChunkName: "login-home-welcom" */ '../components/Home.vue')
// import Welcome from '../components/welcome.vue'
const Welcome = () => import(/* webpackChunkName: "login-home-welcom" */ '../components/welcome.vue')
// import User from '../components/user/User.vue'
const User = () => import(/* webpackChunkName: "user-rights-roles" */ '../components/user/User.vue')
// import Rights from '../components/power/Rights.vue'
const Rights = () => import(/* webpackChunkName: "user-rights-roles" */ '../components/power/Rights.vue')
// import Roles from '../components/power/Roles.vue'
const Roles = () => import(/* webpackChunkName: "user-rights-roles" */ '../components/power/Roles.vue')
// import Cate from '../components/goods/Cate.vue'
const Cate = () => import(/* webpackChunkName: "goods" */ '../components/goods/Cate.vue')
// import Params from '../components/goods/Params.vue'
const Params = () => import(/* webpackChunkName: "goods" */ '../components/goods/Params.vue')
// import List from '../components/goods/List.vue'
const List = () => import(/* webpackChunkName: "goods" */ '../components/goods/List.vue')
// import AddGoods from '../components/goods/AddGood.vue'
const AddGoods = () => import(/* webpackChunkName: "goods" */ '../components/goods/AddGood.vue')
// import Order from '../components/order/Order.vue'
// import Report from '../components/report/Report.vue'
const Order = () => import(/* webpackChunkName: "order-report" */ '../components/order/Order.vue')
const Report = () => import(/* webpackChunkName: "order-report" */ '../components/report/Report.vue')

Vue.use(VueRouter)

const routes = [
  { path: '/', redirect: '/login' },
  { path: '/login', component: Login },
  {
    path: '/home', component: Home, redirect: '/welcome', children: [{
      path: '/welcome', component: Welcome
    }, { path: '/users', component: User }, { path: '/rights', component: Rights }, { path: '/roles', component: Roles }, { path: '/categories', component: Cate }, { path: '/params', component: Params }, { path: '/goods', component: List }, { path: '/addGood', component: AddGoods }, { path: '/orders', component: Order }, { path: '/reports', component: Report }]
  }
]

const router = new VueRouter({
  routes
})
// 添加路由导航守卫
router.beforeEach((to, from, next) => {
  if (to.path === '/login') return next()
  const tokenStr = window.sessionStorage.getItem('token')
  if (tokenStr) return next()
  return next('/login')
})
export default router
